﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Telecom.Service;
using TelecomGis.Helper.Control;

namespace TelecomGis.Framework.Control
{
    public class UTContextgis
    {
        public static readonly string SessionContextKeySC = "Session_Telecom_Gis";
        private readonly UserSer _USerSer = new UserSer();
        private readonly quanhuyenPhuongXaSer _quanhuyenPhuongXaSer = new quanhuyenPhuongXaSer();
        private readonly donviToSer _donviToSer = new donviToSer();

        private UserPageContext UserPageContexts;
        public UserPageContext _UserPageContext
        {
            get
            {
                if (!HttpContext.Current.Request.IsAuthenticated)
                {
                    return null;
                }

                if (UserPageContexts == null)
                {
                    string userName = HttpContext.Current.User.Identity.Name;
                    UserPageContexts = new UserPageContext();
                    UserPageContexts.users = _USerSer.GetByUserName(userName);
                    UserPageContexts.DonViByUser = _donviToSer.ListArayDVByUser(UserPageContexts.users.USERID);
                    UserPageContexts.ToKtByuser = _donviToSer.ListArayTOByUser(UserPageContexts.users.USERID);
                    UserPageContexts.PhuongxaByUser = _quanhuyenPhuongXaSer.GetPhuongXaByTo(UserPageContexts.ToKtByuser);
                    UserPageContexts.QuanHuyenByUser = _quanhuyenPhuongXaSer.ListQuanHuyenByPX(UserPageContexts.PhuongxaByUser);

                    
                }
                return UserPageContexts;
            }
            private set
            {
                UserPageContexts = value;
            }
        }

        

        public void LogOut()
        {
            UserPageContexts = null;
        }

    }
}
